package com.lonewalker.sparrow.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lonewalker.sparrow.convertor.UserConvertor;
import com.lonewalker.sparrow.entity.UserInfo;
import com.lonewalker.sparrow.mapper.UserInfoMapper;
import com.lonewalker.sparrow.req.UserAddReq;
import com.lonewalker.sparrow.req.UserInfoQueryReq;
import com.lonewalker.sparrow.service.UserInfoService;
import org.springframework.stereotype.Service;

/**
 * @author: lonewalker
 */
@Service("userInfoService")
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {
    @Override
    public Page<UserInfo> pageUserInfo(UserInfoQueryReq requestParam) {
        Page<UserInfo> page = new Page<>(requestParam.getPageNum(), requestParam.getPageSize());
        return baseMapper.pageUserInfo(page, requestParam);
    }

    @Override
    public Boolean addUser(UserAddReq req) {
        UserInfo userInfo = UserConvertor.INSTANCE.req2Po(req);
        userInfo.setId(IdWorker.getId());
        return baseMapper.insert(userInfo) > 0;
    }
}
